package com.woniu.microassetserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.microassetserver.mapper.DevTypeMapper;
import com.woniu.microassetserver.service.DevTypeService;
import com.woniu.microcommonsserver.entity.DevTypeEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Transactional(readOnly = true)
@Service
public class DevTypeServiceImpl implements DevTypeService {

    @Resource
    private DevTypeMapper devTypeMapper;

    @Override
    public PageInfo<DevTypeEntity> findAllByParams(int pageNum, int pageSize, DevTypeEntity devTypeEntity) {
        return PageHelper.startPage(pageNum,pageSize).
                doSelectPageInfo(()->devTypeMapper.findAllByParams(devTypeEntity));
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int saveDevType(DevTypeEntity devTypeEntity) {
        return devTypeMapper.saveDevType(devTypeEntity);
    }

    @Override
    public DevTypeEntity getOneById(Long id) {
        return devTypeMapper.getOneById(id);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updateDevType(DevTypeEntity devTypeEntity) {
        return devTypeMapper.updateDevType(devTypeEntity);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int deleteDevType(Long id) {
        return devTypeMapper.deleteDevType(id);
    }
}